<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>
<%@page import="java.util.ArrayList,com.scalar.chiptrack.users.Functionality,
                com.scalar.chiptrack.sales.CustomerPartNumber,
                com.scalar.chiptrack.utils.ConfigManager,
                com.scalar.chiptrack.users.User,
                java.util.HashMap,
                com.scalar.chiptrack.sales.SalesOrder,
                com.scalar.chiptrack.sales.forms.SalesOrderForm" %>
<%
    String chipTracContext = "/" + ConfigManager.getChipTracContext();
    String noOfDecimalsInAmount = ConfigManager.getnoOfDecmalsInAmount()+"";
    String restrictCharsJSFnc = "javascript:restrictCharacters(this,7,"+noOfDecimalsInAmount+")";
    String restrictAmtJSFnc = "javascript:restrictAmt(this,7,"+noOfDecimalsInAmount+")";
    int i= 0;
    int noOfColumnsBeforeQty = 7;
    
%>
<table border="0" width="100%" id="lineItemsTable">
	 <tr>
	    <td width="8%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Line Item</font></td>
        <td width="8%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">PO Line Item&nbsp;*</font></td>
        <td width="20%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF"><bean:message key="label.mfgPartNumber" />&nbsp;*</font></td>
         <% if(ConfigManager.getBooleanProperty(ConfigManager.PROP_SHOW_SALES_LINEITEM_MARKETING_PART_NUMBER)) { %>
            <td width="20%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF"><bean:message key="label.mktgPartNumber" /></font></td>
         <% noOfColumnsBeforeQty ++; } %>
        <td width="20%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF"><bean:message key="label.customerPartNumber"/></font></td>
        <td width="15%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Description</font></td>
        <td width='1%' align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Taxable</font></td>
        <td width="30%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Req'd Dock Date<br><font size="-3">(mm/dd/yyyy)</font>&nbsp;*</font></td>
        <td width="5%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Quantity&nbsp;*</font></td>
        <td width="10%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Price($) </font></td>
        <td width="15%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">Amount</font></td>
        <td width="15%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">&nbsp;Zero&nbsp;<br>&nbsp;Price&nbsp;</font></td>
        <td width="15%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF">&nbsp;Expedite&nbsp;<br>&nbsp;Fee&nbsp;</font></td>
         <%
             if(ConfigManager.getBooleanProperty(ConfigManager.PROP_SHOW_SALES_LINEITEM_CUSTOM_PRICE_FIELD1)) {
         %>
            <td width="15%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF"><bean:message key="label.sales.lineItem.customPriceField1" /></font></td>
         <%
             }
             if(ConfigManager.getBooleanProperty(ConfigManager.PROP_SHOW_SALES_LINEITEM_CUSTOM_TEXT_FIELD1)) {
         %>
                <td width="15%" align="center" bgcolor="#993333" class="NArialL"><font color="#FFFFFF"><bean:message key="label.sales.lineItem.customTextField1" /></font></td>
         <%
             }
         %>
    </tr>
<logic:iterate id="myHashMap" name="lineItemsWithSubtotals">
    <logic:iterate id="lineItemList" name="myHashMap" >
          <logic:iterate id="LineItem" name="lineItemList" indexId="iterateIdx" property="key" type="com.scalar.chiptrack.sales.LineItem">
    <tr>
	    <td width="8%" bgcolor="#DEE1E2">
            <html:text name="LineItem" property="lineItemNo" size='6' styleClass="txfield" disabled="true"/>
            <html:hidden name="LineItem" property="lineItemNo" />
                <input type="hidden" name="jsLineItemNo" value="<%=LineItem.getLineItemNo()%>">
        </td>
        <td width="8%" bgcolor="#DEE1E2">
            <html:text name="LineItem" property="poLineItemNo" size='6' styleClass="txfield" disabled="true"/>
            <html:hidden name="LineItem" property="poLineItemNo" />
        </td>
	    <td width="18%" bgcolor="#DEE1E2" nowrap>
            <input type="text" name="qs<%=i+1%>" class="txfield" size='35' onkeyup="quickSearch(qs_<%=i+1%>)"/><br>            
            <select name="manufacturingPartNo" class="txfield" onChange="getComments(<%=i%>);<% if(ConfigManager.getBooleanProperty(ConfigManager.PROP_SHOW_SALES_LINEITEM_MARKETING_PART_NUMBER)) { %>showMktgPartNumber(<%=i%>);<%}%>">
                <option value="" >Select Part Number</option>
                <%
                      CustomerPartNumber customerPartNo = new  CustomerPartNumber();
                      StringBuffer strBuffer1 = null;
                      java.util.ArrayList mfgList = null;
                      strBuffer1 = new StringBuffer();
                      StringBuffer productsScript = new StringBuffer();

                      HashMap  salesOrderMap = ( HashMap ) session.getAttribute( "salesOrderMap" );
                      if ( salesOrderMap != null ) {
                          com.scalar.chiptrack.sales.forms.SalesOrderForm salesOrderForm1 = (SalesOrderForm)request.getAttribute("salesOrderForm");
                          SalesOrder salesOrderFromMap = (SalesOrder)( salesOrderMap.get( salesOrderForm1.getCustomerId()+"" ));
                          mfgList = salesOrderFromMap.getMfgParts();
                      }
                      for(int k=0;k<mfgList.size();k++)
                      {
                            customerPartNo = (CustomerPartNumber)mfgList.get(k);

                        if( (customerPartNo.getManufacturingPartNo()).equalsIgnoreCase(LineItem .getManufacturingPartNo()) )
                              {
                                  strBuffer1.append("<option value='").append(customerPartNo.getManufacturingPartNo()).append("'selected>");
                              }
                              else
                              {
                                  strBuffer1.append("<option value='").append(customerPartNo.getManufacturingPartNo()).append("'>");
                              }
                            strBuffer1.append(customerPartNo.getManufacturingPartNo()).append("</option>\n");
                          productsScript.append("ct.product.register('"+customerPartNo.getManufacturingPartNo()+"', new ct.Product('"+customerPartNo.getManufacturingPartNo()+"','"+customerPartNo.getMarketingPartNo()+"'));");
                      }
                      out.println(strBuffer1);
                    if(i == 0) {
                        out.println("<script>" +productsScript + "</script>");
                    }
               %>
            </select>
            <%--<a href="javascript:partNoGenerator('<%= iterateIdx.intValue() %>')" ><IMG border="0" src="<%=chipTracContext%>/jsp/includes/images/uparrow.gif" width="20" height="16"></a>--%>
            <input type="hidden" name="partLineItemNo" value="">
        </td>
        <% if(ConfigManager.getBooleanProperty(ConfigManager.PROP_SHOW_SALES_LINEITEM_MARKETING_PART_NUMBER)) { %>
            <td width="18%" bgcolor="#DEE1E2"><span class="NArialL" id="marketingPartNoSpan<%=i%>"><bean:write name="LineItem" property="marketingPartNo"/></span>
                <html:hidden name="LineItem" property="marketingPartNo"/>
            </td>
         <% } %>
        <td width="18%" bgcolor="#DEE1E2">
            <select name="customerPartNo"  class="txfield" onchange="showHideNewCustPartNo(<%=i%>)">
                <option value="">Select Customer Part No</option>
                <%
                      ArrayList customerPartNumbersList = (ArrayList)request.getAttribute( "customerPartNumbers"+LineItem.getLineItemNo());
                      if ( customerPartNumbersList != null )
                      {
                          StringBuffer strBuffer2 = new StringBuffer();
                          for ( int j = 0; j < customerPartNumbersList.size(); j++) {
                              String customerPartNumber =  (String)customerPartNumbersList.get(j);
                              if( (customerPartNumber).equalsIgnoreCase(LineItem .getCustomerPartNo()) )
                              {
                                  strBuffer2.append("<option value='").append(customerPartNumber).append("'selected>");
                              }
                              else
                              {
                                  strBuffer2.append("<option value='").append(customerPartNumber).append("'>");
                              }
                              strBuffer2.append(customerPartNumber).append("</option>\n");
                          }
                          out.println(strBuffer2);
                      }
               %>
                <option value="-2" <%="-2".equals(LineItem .getCustomerPartNo()) ? "selected" : ""%> >--Add New CustomerPart No--</option>
            </select>
                <html:text name="LineItem" property="newCustomerPartNo" style="display:none;" styleClass="txfield" maxlength="50" size="20"/>
        </td>
        <td width="15%" bgcolor="#DEE1E2">
            <input type="hidden" name="">
            <font class="NArialL">
                 <html:textarea name="LineItem" property="lineItemDescription"  styleClass="txfield" onkeydown="javascript:setTextAreaMaxLength(this,200)" onkeyup="javascript:setTextAreaMaxLength(this,200)" />
            </font>
        </td>
        <td width="5%" bgcolor="#DEE1E2" align=center>
            <logic:equal name="LineItem" property="isTaxable" value="true">
                <input type="checkbox" name=isTaxable<bean:write name="LineItem" property="lineItemNo"/> value="on" CHECKED>
            </logic:equal>
            <logic:equal name="LineItem" property="isTaxable" value="false">
                <% if((request.getParameter("isSample") != null) && (request.getParameter("isSample").equals("0"))) { %>
                    <input type="checkbox" name=isTaxable<bean:write name="LineItem" property="lineItemNo"/> value="on" disabled="true">
                <% } else { %>
                    <input type="checkbox" name=isTaxable<bean:write name="LineItem" property="lineItemNo"/> value="on" >
                <% } %>
            </logic:equal>
        </td>
        <td width="17%" bgcolor="#DEE1E2" nowrap>
            <html:text name="LineItem" property="requestDate" size='12' styleClass="txfield"/>
                <a href="javascript:if(document.salesOrderForm.requestDate.length!=null){openCalendar(document.salesOrderForm.requestDate[<bean:write name="LineItem" property="lineItemNo"/>-1])}else{openCalendar(document.salesOrderForm.requestDate)}"><img onMouseOver="window.status='Click here to select date';return true" border="0" align='center' src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20></a>
        </td>
        <td width="5%" bgcolor="#DEE1E2">
            <input type="text" name="quantity" size='8' class="valuetxfield" onkeypress="javascript:allowInteger()" onblur="checkBaseOrderQty(<%=i%>)" maxlength="6" value="<%=LineItem.getQuantity()%>" >
        </td>
        <input type="hidden" name="oldQty" value="<%=LineItem.getQuantity()%>">
        <td width="10%" bgcolor="#DEE1E2">
            <html:text name="LineItem" property="unitPriceAsDouble" size='12' styleClass="valuetxfield" onkeypress="<%=restrictCharsJSFnc%>" maxlength="9" onkeyup="<%=restrictAmtJSFnc%>"/>
        </td>
        <td width="15%" bgcolor="#DEE1E2"><html:text name="LineItem" property="amountAsString" size='25' styleClass="valuetxfield" disabled="true"/></td>
        <td bgcolor="#DEE1E2" align="center">
            <logic:equal name="LineItem" property="zeroPrice" value="true">
                <input type="checkbox" name=zeroPrice<bean:write name="LineItem" property="lineItemNo"/> value="on" onClick="javascript:setZeroPrice( <%=i%>, <bean:write name="LineItem" property="lineItemNo"/> )" CHECKED>
            </logic:equal>
            <logic:equal name="LineItem" property="zeroPrice" value="false">
                <input type="checkbox" name=zeroPrice<bean:write name="LineItem" property="lineItemNo"/> value="on" onClick="javascript:setZeroPrice( <%=i%>, <bean:write name="LineItem" property="lineItemNo"/> )">
            </logic:equal>
         </td>
         <td bgcolor="#DEE1E2" align="center">
            <logic:equal name="LineItem" property="isExpedite" value="true">
                <input type="checkbox" name=expediteFee<bean:write name="LineItem" property="lineItemNo"/> value="on" CHECKED >
            </logic:equal>
            <logic:equal name="LineItem" property="isExpedite" value="false">
                <input type="checkbox" name=expediteFee<bean:write name="LineItem" property="lineItemNo"/> value="on" >
            </logic:equal>
         </td>
         <%
             if(ConfigManager.getBooleanProperty(ConfigManager.PROP_SHOW_SALES_LINEITEM_CUSTOM_PRICE_FIELD1)) {
         %>
            <td width="10%" bgcolor="#DEE1E2">
                <html:text name="LineItem" property="customPriceField1" size='12' styleClass="valuetxfield" onkeypress="<%=restrictCharsJSFnc%>" maxlength="9" onkeyup="<%=restrictAmtJSFnc%>"/>
            </td>
         <%
             }
             if(ConfigManager.getBooleanProperty(ConfigManager.PROP_SHOW_SALES_LINEITEM_CUSTOM_TEXT_FIELD1)) {
         %>
            <td width="15%" bgcolor="#DEE1E2">
                <font class="NArialL">
                     <html:textarea name="LineItem" property="customTextField1"  styleClass="txfield" onkeydown="javascript:setTextAreaMaxLength(this,200)" onkeyup="javascript:setTextAreaMaxLength(this,200)" />
                </font>
            </td>
         <%
             }
         %>
     </tr>
     <% i = i + 1; %>
    </logic:iterate>
    <logic:notEqual parameter="action" value="NewSalesOrder">
        <logic:notEqual parameter="action" value="SearchCustomer">
            <tr>
                <td colspan="<%=noOfColumnsBeforeQty%>" width="15%" bgcolor="#FFFFFF" class="NArialL" align="right">
                        Sub Total
                </td>
                <bean:define id="subTotal" name="lineItemList" property="value" type="com.scalar.chiptrack.sales.SubTotal"/>
                <td colspan="1" width="15%" bgcolor="#FFFFFF" class="NArialL" align="right">
                    <bean:write name="subTotal" property="subTotalQty" />
                </td>
                <td>&nbsp;</td>
                <td colspan="1" width="15%" bgcolor="#FFFFFF" class="NArialL" align="right">
                    <bean:write name="subTotal" property="subTotalAmt" />
                </td>
            </tr>
        </logic:notEqual>
    </logic:notEqual>
   </logic:iterate>
</logic:iterate>

    <tr  id="rowIndex"><td colspan='13' align="left"><FONT id="font1"></FONT></TD></TR>
    <tr><td colspan="13">&nbsp;</td></tr>
    <tr>
        <td colspan="<%=noOfColumnsBeforeQty+2%>" align="right" bgcolor="#FFFFFF" class="NArialL">Total</td>
        <td width="15%" align="left" bgcolor="#FFFFFF">&nbsp;<html:text name="salesOrderForm" property="subTotalAsString" disabled="true" styleClass="valuetxfield" size="25"/></td>
        <td width="15%" align="center" bgcolor="#FFFFFF">&nbsp;</td>
    </tr>
    <%  int salesTaxStateColspan = noOfColumnsBeforeQty-3; %>
    <tr>
        <td colspan="<%=salesTaxStateColspan%>" class="NArialL" align=right>Sales Tax State</td>
        <td class="NArialL">
            <logic:equal parameter="isSample" value="0">
                    <html:select name="salesOrderForm" property="salesTaxType" styleClass="txfield" disabled= "true">
                        <html:option value="0">Non Taxable</html:option>
                        <html:options collection="salesTaxes" property="value" labelProperty="label" />
                    </html:select>
            </logic:equal>
            <logic:notEqual parameter="isSample" value="0">
                <html:select name="salesOrderForm" property="salesTaxType" styleClass="txfield" onchange="javascript:addNewSalesTaxType(this);">
                    <html:option value="0" >Non Taxable</html:option>
                    <html:options collection="salesTaxes" property="value" labelProperty="label" />
                    <html:option value="-1">Others</html:option>
                </html:select>
            </logic:notEqual>
        </td>
        <td colspan=<%=noOfColumnsBeforeQty-salesTaxStateColspan+1%> align=right class="NArialL">Sales Tax</td>
        <td width="15%" class="NArialL" >&nbsp;&nbsp;<html:text name="salesOrderForm" property="salesTaxAsString" styleClass="valuetxfield"  size="25" disabled="true"/></td>
        <td width="15%" align="center" bgcolor="#FFFFFF">&nbsp;</td>
    </tr>
    <tr>
        <td colspan="<%=salesTaxStateColspan%>" align=right class="NArialL"><font class="NArialL"><FONT id="font-1"></FONT></font></td>
        <td class="NarialL" ><font class="NArialL"><FONT id="font-2"></FONT></font></td>
        <td colspan=<%=noOfColumnsBeforeQty-salesTaxStateColspan+1%> align=right class="NArialL">Freight</td>
        <td width="15%" class="NArialL">
        <logic:equal parameter="isSample" value="0">
                $<html:text name="salesOrderForm" property="frieghtAsDouble" styleClass="valuetxfield"  size="25" disabled="true" />
        </logic:equal>
        <logic:notEqual parameter="isSample" value="0">
            $<html:text name="salesOrderForm" property="frieghtAsDouble" styleClass="valuetxfield"  size="25" onkeypress="<%=restrictCharsJSFnc%>" maxlength="9" onkeyup="<%=restrictAmtJSFnc%>" />
        </logic:notEqual>
        </td>
        <td width="15%" align="center" bgcolor="#FFFFFF">&nbsp;</td>
    </tr>
    <tr>
        <td colspan="<%=salesTaxStateColspan%>" align=right class="NArialL"><font class="NArialL"><FONT id="font-3"></FONT></font></td>
        <td class="NarialL" ><font class="NArialL"><FONT id="font-4"></FONT></font></td>
        <td colspan=<%=noOfColumnsBeforeQty-salesTaxStateColspan+1%> align=right class="NArialL"><html:text name="salesOrderForm" property="miscName" styleClass="valuetxfield" /></td>
        <td width="15%" class="NArialL">
        <logic:equal parameter="isSample" value="0">
            $<html:text name="salesOrderForm" property="miscAsDouble" styleClass="valuetxfield" size="25" disabled="true"/>
        </logic:equal>
        <logic:notEqual parameter="isSample" value="0">
            $<html:text name="salesOrderForm" property="miscAsDouble" styleClass="valuetxfield" size="25" maxlength="9" onkeypress="<%=restrictCharsJSFnc%>" onkeyup="<%=restrictAmtJSFnc%>" />
        </logic:notEqual>
        </td>
        <td width="15%" align="center" bgcolor="#FFFFFF">&nbsp;</td>
    </tr>
    <tr>
        <td colspan="<%=noOfColumnsBeforeQty+2%>" align=right class="NArialL">Order Total</td>
        <td width="15%" class="NArialL">&nbsp;&nbsp;<html:text name="salesOrderForm" property="orderTotalAsString" disabled="true" styleClass="valuetxfield" size="25"/></td>
        <td width="15%" align="center" bgcolor="#FFFFFF">&nbsp;</td>
    </tr>
    <tr><td colspan="13">&nbsp;</td></tr>
    <tr>
        <td colspan="<%=noOfColumnsBeforeQty+2%>">&nbsp</td>
        <td align="center"><a href="javascript:addTextArea();"><img src="<%=chipTracContext%>/jsp/includes/images/addmore.gif" border=0 onmouseover="window.status='Click here to Add LineItem';return true" onmouseout="window.status='';return true" title="Click here to Add LineItem"></a></td>
        <td width="15%" align="center">
            <logic:equal parameter="isSample" value="0">
                <chiptrack:restrictedLink functionality='<%=Functionality.SAMPLE_NEW_SAMPLE_ORDER%>' action='<%=User.USER_ACTION_MODIFY%>' href="javascript:submitPage('UPDATE');" onmouseover="window.status='Click here to Calculate Order Total';return true" onmouseout="window.status='';return true"><img src="<%=chipTracContext%>/jsp/includes/images/calculate.gif" border='0' title="Click here to Calculate Order Total"></chiptrack:restrictedLink>
            </logic:equal>
            <logic:notEqual parameter="isSample" value="0">
                <chiptrack:restrictedLink functionality='<%=Functionality.SALES_NEW_SALES_ORDER%>' action='<%=User.USER_ACTION_MODIFY%>' href="javascript:submitPage('UPDATE');" onmouseover="window.status='Click here to Calculate Order Total';return true" onmouseout="window.status='';return true"><img src="<%=chipTracContext%>/jsp/includes/images/calculate.gif" border='0' title="Click here to Calculate Order Total"></chiptrack:restrictedLink>
            </logic:notEqual>
        </td>
        <td width="15%" align="center" bgcolor="#FFFFFF">&nbsp;</td>
    </tr>
</table>

